package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.mapper.ApArticleMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.common.dtos.ResponseResult;
import org.apache.kafka.common.protocol.types.Field;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * create 2023/6/23 11:26
 */


@Service
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {

    /**
     * 文章的上架或下载
     *
     * @param map
     */
    @Override
    public void updateByMap(Map map) {
       String articleId = map.get("articleId").toString();
        Object enable = map.get("enable");
        ApArticleConfig articleConfig = this.getOne(new LambdaQueryWrapper<ApArticleConfig>().eq(ApArticleConfig::getArticleId, Long.valueOf(articleId)));
        if (articleConfig == null) {
            throw new RuntimeException("该文章不存在！");
        }
         boolean isDown=false;
        if (enable.equals(0)) {
            isDown=true;
        }
        articleConfig.setIsDown(isDown);
        this.updateById(articleConfig);
    }
}
